/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simplepushserver.filesend;

import simplepushserver.filesend.DataTimeUnits;
import java.awt.*;
import javax.swing.*;

/**
 *
 * @author Fille
 */
public class TransferProgressBar extends JFrame{

    private static final long serialVersionUID = 0;
    
    private JProgressBar bar;
    public StatisticsJPanel stat;

    private long maxValue=0;
    private long currentVaule=0;
    
    public TransferProgressBar(long max, DataTimeUnits unit){
        maxValue=max;
        bar= new JProgressBar(JProgressBar.HORIZONTAL, 0,100);
        stat= new StatisticsJPanel(this, unit);
        stat.setTimeText(0);
        
        setLayout(new BorderLayout());

        add(bar, BorderLayout.SOUTH);
        add(stat, BorderLayout.NORTH);
        
        bar.setString("0%");
        bar.setStringPainted(true);

        setResizable(false);
        pack();
        setDefaultCloseOperation(HIDE_ON_CLOSE);
    }
    public void setMaxValue(long v){
        maxValue=v;
    }
    public long getMaxValue(){
        return maxValue;
    }
    public void setFilename(String name){
        stat.setFilename(name);
        pack();
    }
    public void startTime(){
        stat.startTime();
    }
    public void stopTime(){
        stat.stopTime();
    }
    public void updateTo(long value){
        currentVaule=value;
        int procent = (int) Math.round(((value*0.1/0.1) / (maxValue*0.1/0.1))*100);
        bar.setValue(procent);
        bar.setString(procent+"%");
        repaint();
    }
    public long getProgress(){
        return currentVaule;
    }

}